package com.fang.active;

import com.fang.bean.UserInfo;

import com.fang.service.IUserInfoService;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class UserInfoAction {
    @Resource
    IUserInfoService iUserInfoService;

    @RequestMapping("/doLogin4")
    public ModelAndView doLogin4(UserInfo userInfo) {
        //打印形参列表
        System.out.println("用户名："+userInfo.getUsername()+",密码："+userInfo.getUserpsw());
        ModelAndView mav = new ModelAndView();
       boolean isOk = iUserInfoService.doLogined(userInfo);
       if(isOk) {
           mav.setViewName("logined");
           mav.addObject("userLoginedName", userInfo.getUsername());
       }else {
           mav.setViewName("../../index");
       }
        // 返回显示视图的路径
        return mav;
    }
    @RequestMapping("/ajaxSelectAction")
    @ResponseBody
    public List<UserInfo> doSelect(UserInfo userInfo){
        List<UserInfo> list = iUserInfoService.doSelect(userInfo);
        return list;
    }
    @RequestMapping("/ajaxAdd")
    @ResponseBody
    public String UpdateAndInsert(UserInfo userInfo){
        String strRenew = null;
       int i = iUserInfoService.UpdateAndInsert(userInfo);
       if(i>0){
           strRenew = "ok";
       }
       return strRenew;
    }
}
